//粒子
class Particle{
    constructor(game){
        this.game=game;
        this.deleteFlag=false;
    }
    update(){
        this.x-=this.speedX+this.game.speed;
        this.y-=this.speedY;;
        this.size*=0.95;
        if(this.size<0.5) this.deleteFlag=true;
    }
}
//烟尘粒子
export class Dust extends Particle{
    constructor(game,x,y){
        super(game);
        this.size=Math.random()*10+10;
        this.x=x;
        this.y=y;
        this.speedX=Math.random();
        this.speedY=Math.random();
        this.color='rgba(0,0,0,0.2)'
    }
    draw(context){
        context.beginPath();
        context.arc(this.x,this.y,this.size,0,Math.PI*2);
        context.fillStyle=this.color;
        context.fill();
    }
}

//火焰粒子
export class Fire extends Particle{
    constructor(game,x,y){
        super(game);
        this.img=document.getElementById('fire')
        this.size=Math.random()*100+100;
        this.x=x;
        this.y=y;
        this.speedX=1
        this.speedY=1;
        this.angle=0;
        this.speedAngle=Math.random()*0.2-0.1;
        
    }
    update(){
        super.update();
        this.angle+=this.speedAngle;
        this.x+=Math.sin(this.angle)
    }
    draw(context){
        context.save();
        context.translate(this.x,this.y);
        context.rotate(this.angle);
        context.drawImage(this.img,-this.game.player.width,-this.game.player.height,this.size,this.size)
        context.restore();
    }
}

//流星飞溅粒子
export class Splash extends Particle{
    constructor(game,x,y){
        super(game);
        this.img=document.getElementById('fire')
        this.size=Math.random()*100+100;
        this.x=x-this.size*0.4;
        this.y=y-this.size*0.5;
        this.speedX=Math.random()*6-4;
        this.speedY=Math.random*2+1;
        this.gravity=0;

        
    }
    update(){
        super.update();
        this.gravity+=0.1;
        this.y+=this.gravity
        
    }
    draw(context){
        context.drawImage(this.img,this.x,this.y,this.size,this.size)
    }
}